#include <rtthread.h>
#include <rtdevice.h>
#include "drv_common.h"
#include <dfs_posix.h>
#include <arpa/inet.h>
#include <netdev.h>         /* 当需要网卡操作是，需要包含这两个头文件 */

int netdev_set_ipaddr_test(int argc, char **argv)
{
    struct netdev *netdev = RT_NULL;
    ip_addr_t addr;
    ip_addr_t netmask;

    if (argc != 3)
    {
        rt_kprintf("netdev_set_ipaddr  [netdev_name] [ip_addr]   --set network interface device IP address.\n");
        return -1;
    }

    /* 通过名称获取网卡对象 */
    netdev = netdev_get_by_name(argv[1]);
    if (netdev == RT_NULL)
    {
        rt_kprintf("input network interface name(%s) error.\n", argv[1]);
        return -1;
    }

    /*  设置DHCP */
    netdev_dhcp_enabled(netdev,RT_FALSE);


    /*  设置网卡 IP 地址*/
    inet_aton(argv[2], &addr);
    netdev_set_ipaddr(netdev, &addr);
    inet_aton("255.255.255.0", &netmask);
    netdev_set_netmask(netdev,&netmask);

    return 0;
}
#ifdef FINSH_USING_MSH
#include <finsh.h>
/* 导出命令到 FinSH 控制台 */
MSH_CMD_EXPORT_ALIAS(netdev_set_ipaddr_test, netdev_set_ipaddr, set network interface device IP address);
#endif /* FINSH_USING_MSH */
